"use strict";
const common_vendor = require("../../common/vendor.js");
const common_request = require("../../common/request.js");
const uSwiper = () => "../../components/u-swiper/u-swiper.js";
const _sfc_main = {
  components: {
    uSwiper
  },
  onShareAppMessage() {
    return {
      title: "产品详情",
      imageUrl: "",
      path: "/pages/goods-detail/goods-detail?id=" + this.goodsId
    };
  },
  data() {
    return {
      showError: false,
      goodsId: "",
      features: [],
      prevIndex: 0,
      canshucColor: "",
      dynamicColor: "",
      logoBanner: "/static/arcbg.png",
      goodsData: {}
    };
  },
  onLoad(options) {
    const { id } = options;
    if (id) {
      this.goodsId = id;
      this.getDetail();
      this.getImagePath();
    }
    console.log("进入了商品");
  },
  methods: {
    changeIndex(index) {
      this.prevIndex = index;
    },
    getImagePath() {
      common_request.service({
        url: "/category/imgbanner?id=" + this.goodsId
      }).then((res) => {
        if (res) {
          this.logoBanner = res;
          if (this.logoBanner === "/static/arcbg1.jpg") {
            this.dynamicColor = "aliceblue";
            this.canshucColor = "#002855";
          }
        }
      });
    },
    lookImage(index) {
      common_vendor.index.previewImage({
        current: index,
        urls: this.goodsData.images,
        longPressActions: {
          itemList: ["发送给朋友", "保存图片", "收藏"],
          success: function(data) {
            console.log(data);
          },
          fail: function(err) {
            console.log(err.errMsg);
          }
        }
      });
    },
    getHtml(str) {
      if (!str)
        return "";
      let domain = "https://fullhouse.qinyuan.cn";
      let newHtmlStr = str.replace(/src="\/uploads/g, `src="${domain}/uploads`);
      var newContent = newHtmlStr.replace(/<img[^>]*>/gi, (match) => {
        let processed = null;
        if (!match.match(/style=\"(.*)\"/gi)) {
          processed = match.replace(/\<img/g, '<img style="width:100%;height:auto;display:block"');
        } else {
          processed = match.replace(/style=\"(.*)\"/gi, 'style="width:100%;height:auto;display:block"');
        }
        return processed;
      });
      return newContent;
    },
    getFeatures(str) {
      if (!str)
        return [];
      return str.split(",").map((e) => {
        const arr = e.split(":");
        return {
          label: arr[0] || "-",
          value: arr[1] || "-"
        };
      });
    },
    getDetail() {
      common_request.service({
        url: "/category/products?id=" + this.goodsId
        // params: {
        // 	id: this.goodsId
        // }
      }).then((res) => {
        if (!res || !res.length)
          return;
        this.goodsData = res[0];
        this.features = this.getFeatures(this.goodsData.attributes);
        if (this.goodsData.image) {
          const host = "https://fullhouse.qinyuan.cn";
          if (Array.isArray(this.goodsData.image)) {
            this.goodsData.images = this.goodsData.image.map((e) => host + e);
          } else {
            this.goodsData.images = [this.goodsData.image, this.goodsData.image].map((e) => host + e);
          }
        }
      });
    }
  }
};
if (!Array) {
  const _easycom_u_swiper2 = common_vendor.resolveComponent("u-swiper");
  _easycom_u_swiper2();
}
const _easycom_u_swiper = () => "../../components/u-swiper/u-swiper.js";
if (!Math) {
  _easycom_u_swiper();
}
function _sfc_render(_ctx, _cache, $props, $setup, $data, $options) {
  return common_vendor.e({
    a: $data.logoBanner,
    b: common_vendor.t($data.goodsData.name),
    c: $data.dynamicColor,
    d: $data.goodsData.images && $data.goodsData.images.length > 1
  }, $data.goodsData.images && $data.goodsData.images.length > 1 ? {
    e: common_vendor.o(($event) => $options.lookImage($data.prevIndex)),
    f: common_vendor.o($options.changeIndex),
    g: common_vendor.p({
      list: $data.goodsData.images,
      ["img-mode"]: "heightFix",
      height: "360",
      autoplay: false
    })
  } : $data.goodsData.images && $data.goodsData.images.length === 1 ? {
    i: $data.goodsData.images[0]
  } : {}, {
    h: $data.goodsData.images && $data.goodsData.images.length === 1,
    j: $options.getHtml($data.goodsData.description),
    k: $data.canshucColor,
    l: common_vendor.f($data.features, (item, k0, i0) => {
      return {
        a: common_vendor.t(item.label),
        b: $options.getHtml(item.value),
        c: common_vendor.s(item.style || {})
      };
    }),
    m: $data.canshucColor,
    n: $options.getHtml($data.goodsData.particulars)
  });
}
const MiniProgramPage = /* @__PURE__ */ common_vendor._export_sfc(_sfc_main, [["render", _sfc_render], ["__file", "C:/Users/karo/Desktop/finale/3.0/clean-water/clean-water/pages/goods-detail/goods-detail.vue"]]);
_sfc_main.__runtimeHooks = 2;
wx.createPage(MiniProgramPage);
